//
//  PendingInfoViewController.m
//  DaiShengInvest
//
//  Created by 张睿 on 2017/7/21.
//  Copyright © 2017年 davinci. All rights reserved.
//

#import "PendingInfoViewController.h"
#import "ChangeViewController.h"

@interface PendingInfoViewController ()

@property (nonatomic, weak)UIImageView * backImageView;
@property (nonatomic, weak)UILabel * trandTypeLabel;
@property (nonatomic, weak)UILabel * trandTypeValueLabel;
@property (nonatomic, weak)UILabel * orderNumberLabel;
@property (nonatomic, weak)UILabel * orderNumberValueLabel;
@property (nonatomic, weak)UILabel * pendingTypeLabel;
@property (nonatomic, weak)UILabel * pendingTypeValueLabel;
@property (nonatomic, weak)UILabel * pendingPriceLabel;
@property (nonatomic, weak)UILabel * pendingPriceValueLabel;
@property (nonatomic, weak)UILabel * stopLosePriceLabel;
@property (nonatomic, weak)UILabel * stopLosePriceValueLabel;
@property (nonatomic, weak)UILabel * stopWinPriceLabel;
@property (nonatomic, weak)UILabel * stopWinPriceValueLabel;
@property (nonatomic, weak)UILabel * pendingTimeLabel;
@property (nonatomic, weak)UILabel * pendingTimeValueLabel;
@property (nonatomic, weak)UILabel * stopTimeLabel;
@property (nonatomic, weak)UILabel * stopTimeValueLabel;
@property (nonatomic, weak)UIView * lineView;
//@property (nonatomic, weak)UILabel * nowPriceLabel;
//@property (nonatomic, weak)UILabel * nowPriceValueLabel;
@property (nonatomic, weak)UIButton * settingButton;
@property (nonatomic, weak)UIButton * cancelButton;
@property (nonatomic, copy)NSString * orderDirection;


@property (nonatomic, strong)NSArray * fiveArray;
@property (nonatomic, strong)NSArray * threeArray;
@property (nonatomic, strong)NSArray * twoArray;


@end

//#define kStringIsEmpty(str)     ([str isKindOfClass:[NSNull class]] || str == nil || [str length] < 1 ? YES : NO )

#define kStringIsEmpty(string) ((![string isKindOfClass:[NSString class]])||[string isEqualToString:@""] || (string == nil) || [string isEqualToString:@""] || [string isKindOfClass:[NSNull class]]||[[string stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]] length]==0)

@implementation PendingInfoViewController


- (void)viewWillAppear:(BOOL)animated{
    
    [MBProgressHUD showHUDAddedTo:self.view animated:YES];
    
    NSDictionary * parameters = @{@"orderId":self.orderId};
    
    [[NetworkTool sharedTools] POST:@"symbols/orders-detail" parameters:parameters progress:nil success:^(NSURLSessionDataTask * _Nonnull task, NSDictionary *  _Nullable responseObject) {
        
        NSLog(@"==%@",responseObject);
        
        [MBProgressHUD hideHUDForView:self.view animated:YES];
        
        NSDictionary * dict = responseObject[@"param"];
//        NSDictionary * priceDict = dict[@"price"];
        
//        NSString * timeString = [NSString stringWithFormat:@"%@",priceDict[@"time"]];
//        expirationDate
//        if([[dict allKeys] containsObject:@"expirationDate"])
//            
//        {
//            NSString * orderTime = [NSString stringWithFormat:@"%@",dict[@"expirationDate"]];
//            NSArray * timeArray = [orderTime componentsSeparatedByString:@"T"];
//            NSString * date = timeArray.firstObject;
//            NSString * time = timeArray.lastObject;
//            NSString * relTime = [time substringToIndex:8];
//            
//            self.stopTimeValueLabel.text = [NSString stringWithFormat:@"%@ %@",date,relTime];
//            
//        }else{
//            
//            self.stopTimeValueLabel.text = @"未设置";
//        }
        
        NSString * dateString = [NSString stringWithFormat:@"%@",dict[@"expirationDate"]];
        
        if ([dateString isEqualToString:@""]) {
            self.stopTimeValueLabel.text = @"未设置";
        }else{
            
//            NSString * orderTime = [NSString stringWithFormat:@"%@",dict[@"expirationDate"]];
            NSArray * timeArray = [dateString componentsSeparatedByString:@"T"];
            NSString * date = timeArray.firstObject;
            NSString * time = timeArray.lastObject;
            NSString * relTime = [time substringToIndex:8];
            
            self.stopTimeValueLabel.text = [NSString stringWithFormat:@"%@ %@",date,relTime];
        }
        

//        NSTimeInterval second = timeString.longLongValue;
//        
//        NSDateFormatter *matter = [[NSDateFormatter alloc]init];
//        matter.dateFormat =@"YYYY-MM-dd HH:mm:ss";
//        NSDate *dateString = [NSDate dateWithTimeIntervalSince1970:second];
//        NSString*timeStr = [matter stringFromDate:dateString];
        
//        NSString * orderType = [NSString stringWithFormat:@"%@",dict[@"orderType"]];
        
//        self.stopTimeValueLabel.text = timeStr;

        
        self.trandTypeValueLabel.text = [NSString stringWithFormat:@"%@",dict[@"symbol"]];
        self.orderNumberValueLabel.text = self.orderId;
        self.pendingTypeValueLabel.text = [NSString stringWithFormat:@"%@",dict[@"volume"]];
        self.orderDirection = [NSString stringWithFormat:@"%@",dict[@"orderDirection"]];
        
        BOOL isFivebool = [self.fiveArray containsObject:self.trandTypeValueLabel.text];
        BOOL isThreebool = [self.threeArray containsObject:self.trandTypeValueLabel.text];
        BOOL isTwobool = [self.twoArray containsObject:self.trandTypeValueLabel.text];
        
        float orderPrice = [dict[@"orderPrice"] floatValue];
        float stopLoss = [dict[@"stopLoss"] floatValue];
        float takeProfit = [dict[@"takeProfit"] floatValue];
        
        if (isFivebool) {
            
           self.pendingPriceValueLabel.text = [NSString stringWithFormat:@"%.5f",orderPrice];
            
            if (stopLoss == 0) {
                
                self.stopLosePriceValueLabel.text = @"未设置";
                
            }else{
                
                self.stopLosePriceValueLabel.text = [NSString stringWithFormat:@"%.5f",stopLoss];
            }
            
            if (takeProfit == 0) {
                
                self.stopWinPriceValueLabel.text = @"未设置";
            }else{
                
                self.stopWinPriceValueLabel.text = [NSString stringWithFormat:@"%.5f",takeProfit];;
            }
        }
        
        if (isThreebool) {
            
            self.pendingPriceValueLabel.text = [NSString stringWithFormat:@"%.3f",orderPrice];
            
            if (stopLoss == 0) {
                
                self.stopLosePriceValueLabel.text = @"未设置";
                
            }else{
                
                self.stopLosePriceValueLabel.text = [NSString stringWithFormat:@"%.3f",stopLoss];
            }
            
            if (takeProfit == 0) {
                
                self.stopWinPriceValueLabel.text = @"未设置";
            }else{
                
                self.stopWinPriceValueLabel.text = [NSString stringWithFormat:@"%.3f",takeProfit];;
            }
        }
        
        if (isTwobool) {
            
            self.pendingPriceValueLabel.text = [NSString stringWithFormat:@"%.2f",orderPrice];
            
            if (stopLoss == 0) {
                
                self.stopLosePriceValueLabel.text = @"未设置";
                
            }else{
                
                self.stopLosePriceValueLabel.text = [NSString stringWithFormat:@"%.2f",stopLoss];
            }
            
            if (takeProfit == 0) {
                
                self.stopWinPriceValueLabel.text = @"未设置";
            }else{
                
                self.stopWinPriceValueLabel.text = [NSString stringWithFormat:@"%.2f",takeProfit];;
            }
        }
        
        
//        NSString *stopLoss = [NSString stringWithFormat:@"%@",dict[@"stopLoss"]];
//        NSString *takeProfit = [NSString stringWithFormat:@"%@",dict[@"takeProfit"]];
        
//        NSLog(@"==%lu",(unsigned long)stopLoss.length);
        
        NSString * orderTime = [NSString stringWithFormat:@"%@",dict[@"dateTime"]];
        NSArray * timeArray = [orderTime componentsSeparatedByString:@"T"];
        NSString * date = timeArray.firstObject;
        NSString * time = timeArray.lastObject;
        NSString * relTime = [time substringToIndex:8];
        
        self.pendingTimeValueLabel.text = [NSString stringWithFormat:@"%@ %@",date,relTime];
        
        } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
            
           [MBProgressHUD hideHUDForView:self.view animated:YES];
        
    }];
}



- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    self.fiveArray = @[@"EURUSDapp",@"NZDUSDapp",@"EURCADapp",@"USDCADapp",@"EURNZDapp",@"AUDNZDapp",@"AUDUSDapp",@"AUDCADapp",@"GBPCHFapp",@"EURAUDapp",@"EURGBPapp",@"CADCHFapp",@"GBPAUDapp",@"EURCHFapp",@"USDCHFapp",@"GBPCADapp",@"GBPNZDapp",@"AUDCHFapp",@"GBPUSDapp"];
    self.threeArray = @[@"XAGUSDapp",@"GBPJPYapp",@"AUDJPYapp",@"USDJPYapp",@"EURJPYapp",@"CADJPYapp",@"NZDJPYapp"];
    self.twoArray = @[@"XAUUSDapp"];
    
    [self setupNavBar];
    [self setupUI];
}

- (void)setupNavBar{
    
    self.title = @"挂单详情";
    
    UIButton * backButton = [[UIButton alloc] init];
    
    backButton.frame = CGRectMake(15 * SCREENH6, 5 * SCREENH6, 12 * SCREENH6, 20 * SCREENH6);
    [backButton setImage:[UIImage imageNamed:@"1返回"] forState:UIControlStateNormal];
    [backButton addTarget:self action:@selector(backToAccountView) forControlEvents:UIControlEventTouchUpInside];
    
    UIBarButtonItem * leftButton = [[UIBarButtonItem alloc] initWithCustomView:backButton];
    
    self.navigationItem.leftBarButtonItem = leftButton;
}

- (void)setupUI{
    
    UIImageView * backImage = [[UIImageView alloc] init];
    
    backImage.image = [UIImage imageNamed:@"背景"];
    
    self.backImageView = backImage;
    
    [self.view addSubview:self.backImageView];
    
    [self.backImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.trailing.bottom.trailing.mas_equalTo(self.view);
    }];
    
    UILabel * trandTypeLabel = [UILabel new];
    
    trandTypeLabel.font = [UIFont fontWithName:@"PingFangSC-Regular" size:14 * SCREENH6];
    trandTypeLabel.textColor = ColorWithRGB(0xa2a2a2);
    trandTypeLabel.textAlignment = NSTextAlignmentLeft;
    trandTypeLabel.text = @"交易品种";
    
    self.trandTypeLabel = trandTypeLabel;
    
    [self.view addSubview:self.trandTypeLabel];
    
    [self.trandTypeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.mas_equalTo(self.view).offset(15 * SCREENH6);
        make.top.mas_equalTo(self.view).offset(84 * SCREENH6);
    }];
    
    
    UILabel * trandTypeValueLabel = [UILabel new];
    
    trandTypeValueLabel.font = [UIFont fontWithName:@"PingFangSC-Regular" size:14 * SCREENH6];
    trandTypeValueLabel.textColor = ColorWithRGB(0xffffff);
    trandTypeValueLabel.textAlignment = NSTextAlignmentLeft;
//    trandTypeValueLabel.text = @"USDCNH";
    
    self.trandTypeValueLabel = trandTypeValueLabel;
    
    [self.view addSubview:self.trandTypeValueLabel];
    
    [self.trandTypeValueLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.mas_equalTo(self.trandTypeLabel.mas_trailing).offset(10 * SCREENH6);
        make.centerY.mas_equalTo(self.trandTypeLabel);
    }];
    
    
    UILabel * orderNumberLabel = [UILabel new];
    
    orderNumberLabel.font = [UIFont fontWithName:@"PingFangSC-Regular" size:14 * SCREENH6];
    orderNumberLabel.textColor = ColorWithRGB(0xa2a2a2);
    orderNumberLabel.textAlignment = NSTextAlignmentLeft;
    orderNumberLabel.text = @"订单编号";
    
    self.orderNumberLabel = orderNumberLabel;
    
    [self.view addSubview:self.orderNumberLabel];
    
    [self.orderNumberLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.mas_equalTo(self.trandTypeValueLabel.mas_trailing).offset(85 * SCREENH6);
        make.centerY.mas_equalTo(self.trandTypeValueLabel);
    }];
    
    
    UILabel * orderNumberValueLabel = [UILabel new];
    
    orderNumberValueLabel.font = [UIFont fontWithName:@"PingFangSC-Regular" size:14 * SCREENH6];
    orderNumberValueLabel.textColor = ColorWithRGB(0xa2a2a2);
    orderNumberValueLabel.textAlignment = NSTextAlignmentLeft;
//    orderNumberValueLabel.text = @"20147";
    
    self.orderNumberValueLabel = orderNumberValueLabel;
    
    [self.view addSubview:self.orderNumberValueLabel];
    
    [self.orderNumberValueLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.mas_equalTo(self.orderNumberLabel.mas_trailing).offset(10 * SCREENH6);
        make.centerY.mas_equalTo(self.orderNumberLabel);
    }];
    
    
    UILabel * pendingTypeLabel = [UILabel new];
    
    pendingTypeLabel.font = [UIFont fontWithName:@"PingFangSC-Regular" size:14 * SCREENH6];
    pendingTypeLabel.textColor = ColorWithRGB(0xa2a2a2);
    pendingTypeLabel.textAlignment = NSTextAlignmentLeft;
    pendingTypeLabel.text = @"挂单手数";
    
    self.pendingTypeLabel = pendingTypeLabel;
    
    [self.view addSubview:self.pendingTypeLabel];
    
    [self.pendingTypeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.mas_equalTo(self.trandTypeLabel);
        make.top.mas_equalTo(self.trandTypeLabel.mas_bottom).offset(15 * SCREENH6);
    }];
    
    
    UILabel * pendingTypeValueLabel = [UILabel new];
    
    pendingTypeValueLabel.font = [UIFont fontWithName:@"PingFangSC-Regular" size:14 * SCREENH6];
    pendingTypeValueLabel.textColor = RED_COLOR;
    pendingTypeValueLabel.textAlignment = NSTextAlignmentLeft;
//    pendingTypeValueLabel.text = @"0.01";
    
    self.pendingTypeValueLabel = pendingTypeValueLabel;
    
    [self.view addSubview:self.pendingTypeValueLabel];
    
    [self.pendingTypeValueLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.mas_equalTo(self.trandTypeValueLabel);
        make.centerY.mas_equalTo(self.pendingTypeLabel);
    }];
    
    UILabel * pendingPriceLabel = [UILabel new];
    
    pendingPriceLabel.font = [UIFont fontWithName:@"PingFangSC-Regular" size:14 * SCREENH6];
    pendingPriceLabel.textColor = ColorWithRGB(0xa2a2a2);
    pendingPriceLabel.textAlignment = NSTextAlignmentLeft;
    pendingPriceLabel.text = @"挂单价格";
    
    self.pendingPriceLabel = pendingPriceLabel;
    
    [self.view addSubview:self.pendingPriceLabel];
    
    [self.pendingPriceLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.mas_equalTo(self.orderNumberLabel);
        make.centerY.mas_equalTo(self.pendingTypeValueLabel);
    }];
    
    
    UILabel * pendingPriceValueLabel = [UILabel new];
    
    pendingPriceValueLabel.font = [UIFont fontWithName:@"PingFangSC-Regular" size:14 * SCREENH6];
    pendingPriceValueLabel.textColor = ColorWithRGB(0xffffff);
    pendingPriceValueLabel.textAlignment = NSTextAlignmentLeft;
//    pendingPriceValueLabel.text = @"$10.00";
    
    self.pendingPriceValueLabel = pendingPriceValueLabel;
    
    [self.view addSubview:self.pendingPriceValueLabel];
    
    [self.pendingPriceValueLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.mas_equalTo(self.orderNumberValueLabel);
        make.centerY.mas_equalTo(self.pendingPriceLabel);
    }];
    
    
    UILabel * stopLosePriceLabel = [UILabel new];
    
    stopLosePriceLabel.font = [UIFont fontWithName:@"PingFangSC-Regular" size:14 * SCREENH6];
    stopLosePriceLabel.textColor = ColorWithRGB(0xa2a2a2);
    stopLosePriceLabel.textAlignment = NSTextAlignmentLeft;
    stopLosePriceLabel.text = @"止损价格";
    
    self.stopLosePriceLabel = stopLosePriceLabel;
    
    [self.view addSubview:self.stopLosePriceLabel];
    
    [self.stopLosePriceLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.mas_equalTo(self.pendingTypeLabel);
        make.top.mas_equalTo(self.pendingTypeLabel.mas_bottom).offset(15 * SCREENH6);
    }];

    
    UILabel * stopLosePriceValueLabel = [UILabel new];
    
    stopLosePriceValueLabel.font = [UIFont fontWithName:@"PingFangSC-Regular" size:14 * SCREENH6];
    stopLosePriceValueLabel.textColor = RED_COLOR;
    stopLosePriceValueLabel.textAlignment = NSTextAlignmentLeft;
//    stopLosePriceValueLabel.text = @"6.78921";
    
    self.stopLosePriceValueLabel = stopLosePriceValueLabel;
    
    [self.view addSubview:self.stopLosePriceValueLabel];
    
    [self.stopLosePriceValueLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.mas_equalTo(self.pendingTypeValueLabel);
        make.centerY.mas_equalTo(self.stopLosePriceLabel);
    }];
    
    
    UILabel * stopWinPriceLabel = [UILabel new];
    
    stopWinPriceLabel.font = [UIFont fontWithName:@"PingFangSC-Regular" size:14 * SCREENH6];
    stopWinPriceLabel.textColor = ColorWithRGB(0xa2a2a2);
    stopWinPriceLabel.textAlignment = NSTextAlignmentLeft;
    stopWinPriceLabel.text = @"止盈价格";
    
    self.stopWinPriceLabel = stopWinPriceLabel;
    
    [self.view addSubview:self.stopWinPriceLabel];
    
    [self.stopWinPriceLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.mas_equalTo(self.pendingPriceLabel);
        make.centerY.mas_equalTo(self.stopLosePriceValueLabel);
    }];
    
    
    UILabel * stopWinPriceValueLabel = [UILabel new];
    
    stopWinPriceValueLabel.font = [UIFont fontWithName:@"PingFangSC-Regular" size:14 * SCREENH6];
    stopWinPriceValueLabel.textColor = RED_COLOR;
    stopWinPriceValueLabel.textAlignment = NSTextAlignmentLeft;
//    stopWinPriceValueLabel.text = @"6.78921";
    
    self.stopWinPriceValueLabel = stopWinPriceValueLabel;
    
    [self.view addSubview:self.stopWinPriceValueLabel];
    
    [self.stopWinPriceValueLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.mas_equalTo(self.pendingPriceValueLabel);
        make.centerY.mas_equalTo(self.stopWinPriceLabel);
    }];

    
    UILabel * pendingTimeLabel = [UILabel new];
    
    pendingTimeLabel.font = [UIFont fontWithName:@"PingFangSC-Regular" size:14 * SCREENH6];
    pendingTimeLabel.textColor = ColorWithRGB(0xa2a2a2);
    pendingTimeLabel.textAlignment = NSTextAlignmentLeft;
    pendingTimeLabel.text = @"挂单时间";
    
    self.pendingTimeLabel = pendingTimeLabel;
    
    [self.view addSubview:self.pendingTimeLabel];
    
    [self.pendingTimeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.mas_equalTo(self.stopLosePriceLabel);
        make.top.mas_equalTo(self.stopLosePriceLabel.mas_bottom).offset(15 * SCREENH6);
    }];
    
    
    UILabel * pendingTimeValueLabel = [UILabel new];
    
    pendingTimeValueLabel.font = [UIFont fontWithName:@"PingFangSC-Regular" size:14 * SCREENH6];
    pendingTimeValueLabel.textColor = ColorWithRGB(0xa2a2a2);
    pendingTimeValueLabel.textAlignment = NSTextAlignmentLeft;
//    pendingTimeValueLabel.text = @"2017.07.20 17:33:00";
    
    self.pendingTimeValueLabel = pendingTimeValueLabel;
    
    [self.view addSubview:self.pendingTimeValueLabel];
    
    [self.pendingTimeValueLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.mas_equalTo(self.stopLosePriceValueLabel);
        make.centerY.mas_equalTo(self.pendingTimeLabel);
    }];
    
    
    UILabel * stopTimeLabel = [UILabel new];
    
    stopTimeLabel.font = [UIFont fontWithName:@"PingFangSC-Regular" size:14 * SCREENH6];
    stopTimeLabel.textColor = ColorWithRGB(0xa2a2a2);
    stopTimeLabel.textAlignment = NSTextAlignmentLeft;
    stopTimeLabel.text = @"截止时间";
    
    self.stopTimeLabel = stopTimeLabel;
    
    [self.view addSubview:self.stopTimeLabel];
    
    [self.stopTimeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.mas_equalTo(self.pendingTimeLabel);
        make.top.mas_equalTo(self.pendingTimeLabel.mas_bottom).offset(15 * SCREENH6);
    }];
    
    
    UILabel * stopTimeValueLabel = [UILabel new];
    
    stopTimeValueLabel.font = [UIFont fontWithName:@"PingFangSC-Regular" size:14 * SCREENH6];
    stopTimeValueLabel.textColor = ColorWithRGB(0xa2a2a2);
    stopTimeValueLabel.textAlignment = NSTextAlignmentLeft;
//    stopTimeValueLabel.text = @"2017.07.20 17:33:00";
    
    self.stopTimeValueLabel = stopTimeValueLabel;
    
    [self.view addSubview:self.stopTimeValueLabel];
    
    [self.stopTimeValueLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.mas_equalTo(self.pendingTimeValueLabel);
        make.centerY.mas_equalTo(self.stopTimeLabel);
    }];
    
    UIView * lineView = [UIView new];
    
    lineView.backgroundColor = [UIColor whiteColor];
    lineView.alpha = 0.1;
    
    self.lineView = lineView;
    
    [self.view addSubview:self.lineView];
    
    [self.lineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.trailing.mas_equalTo(self.view);
        make.height.mas_equalTo(1 * SCREENH6);
        make.top.mas_equalTo(self.stopTimeValueLabel.mas_bottom).offset(10 * SCREENH6);
    }];
    
    
//    UILabel * nowPriceValueLabel = [UILabel new];
//    
//    nowPriceValueLabel.font = [UIFont fontWithName:@"PingFangSC-Medium" size:15 * SCREENH6];
//    nowPriceValueLabel.textColor = RED_COLOR;
//    nowPriceValueLabel.textAlignment = NSTextAlignmentLeft;
////    nowPriceValueLabel.text = @"6.78921";
//    
//    self.nowPriceValueLabel = nowPriceValueLabel;
//    
//    [self.view addSubview:self.nowPriceValueLabel];
//    
//    [self.nowPriceValueLabel mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.leading.mas_equalTo(self.view).offset(80 * SCREENH6);
//        make.bottom.mas_equalTo(self.view).offset(- 40 * SCREENH6);
//    }];
//    
//    
//    UILabel * nowPriceLabel = [UILabel new];
//    
//    nowPriceLabel.font = [UIFont fontWithName:@"PingFangSC-Regular" size:14 * SCREENH6];
//    nowPriceLabel.textColor = ColorWithRGB(0xffffff);
//    nowPriceLabel.textAlignment = NSTextAlignmentLeft;
//    nowPriceLabel.text = @"现价";
//    
//    self.nowPriceLabel = nowPriceLabel;
//    
//    [self.view addSubview:self.nowPriceLabel];
//    
//    [self.nowPriceLabel mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.leading.mas_equalTo(self.nowPriceValueLabel.mas_trailing).offset(5 * SCREENH6);
//        make.centerY.mas_equalTo(self.nowPriceValueLabel);
//    }];
    
    
    
    UIButton * settingButton = [UIButton new];
    
    [settingButton setImage:[UIImage imageNamed:@"设置盈亏1"] forState:UIControlStateNormal];
    [settingButton addTarget:self action:@selector(didSettingButton) forControlEvents:UIControlEventTouchUpInside];
    
    self.settingButton = settingButton;
    
    [self.view addSubview:self.settingButton];
    
    [self.settingButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.mas_equalTo(self.view).offset(15 * SCREENH6);
        make.bottom.mas_equalTo(self.view).offset(-40 * SCREENH6);
        make.width.mas_equalTo(167 * SCREENH6);
        make.height.mas_equalTo(35 * SCREENH6);
    }];
    
    
    UIButton * cancelButton = [UIButton new];
    
    [cancelButton setImage:[UIImage imageNamed:@"取消挂单1"] forState:UIControlStateNormal];
    [cancelButton addTarget:self action:@selector(didCancelButton) forControlEvents:UIControlEventTouchUpInside];
    
    self.cancelButton = cancelButton;
    
    [self.view addSubview:self.self.cancelButton];
    
    [self.cancelButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(self.settingButton);
        make.trailing.mas_equalTo(self.view).offset(-15 * SCREENH6);
        make.width.mas_equalTo(167 * SCREENH6);
        make.height.mas_equalTo(35 * SCREENH6);
    }];

}



//点击设置盈亏
- (void)didSettingButton{
    
    self.hidesBottomBarWhenPushed = YES;
    
    ChangeViewController * changeVC = [ChangeViewController new];
    
    changeVC.positionId = self.orderId;
    changeVC.pirceString = self.pendingPriceValueLabel.text;
    changeVC.typeString = self.orderDirection;
    changeVC.type = @"1";
    
    [self.navigationController pushViewController:changeVC animated:YES];
    
}


- (void)didCancelButton{
    
    [MBProgressHUD showHUDAddedTo:self.view animated:YES];
    
//    NSLog(@"==%@",self.orderId);
    
    NSDictionary * parameters = @{@"orderId":self.orderId};
    
    [[NetworkTool sharedTools] POST:@"symbols/delete-orders" parameters:parameters progress:nil success:^(NSURLSessionDataTask * _Nonnull task, NSDictionary *  _Nullable responseObject) {
        
        NSLog(@"==%@",responseObject);
        
        [MBProgressHUD hideHUDForView:self.view animated:YES];
        
        NSString * code = [NSString stringWithFormat:@"%@",responseObject[@"code"]];
        
        if ([code isEqualToString:@"0"]) {
            
            
            UIAlertController* alert = [UIAlertController alertControllerWithTitle:@""
                                                                           message:@"恭喜你，取消成功！"
                                                                    preferredStyle:UIAlertControllerStyleAlert];
            
            UIAlertAction* defaultAction = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleCancel
                                                                  handler:^(UIAlertAction * action) {
                                                                      //响应事件
                                                                      [self.navigationController popViewControllerAnimated:YES];
                                                                      
                                                                  }];
            
            [alert addAction:defaultAction];
            [self presentViewController:alert animated:YES completion:nil];
        }else{
            
            UIAlertController* alert = [UIAlertController alertControllerWithTitle:@""
                                                                           message:responseObject[@"msg"]
                                                                    preferredStyle:UIAlertControllerStyleAlert];
            
            UIAlertAction* defaultAction = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleCancel
                                                                  handler:^(UIAlertAction * action) {
                                                                      //响应事件
                                                                      
                                                                  }];
            
            [alert addAction:defaultAction];
            [self presentViewController:alert animated:YES completion:nil];
        }
        
        
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        
        [MBProgressHUD hideHUDForView:self.view animated:YES];
        
        UIAlertController* alert = [UIAlertController alertControllerWithTitle:@""
                                                                       message:@"服务器内部错误，请稍后再试。"
                                                                preferredStyle:UIAlertControllerStyleAlert];
        
        UIAlertAction* defaultAction = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleCancel
                                                              handler:^(UIAlertAction * action) {
                                                                  //响应事件
                                                                  
                                                              }];
        
        [alert addAction:defaultAction];
        [self presentViewController:alert animated:YES completion:nil];
    }];
    
    
}


//- (BOOL)StringIsNullOrEmpty:(NSString *)str
//{
//    return (str == nil || [str isKindOfClass:[NSNull class]] || str.length == 0);
//}


//-(NSString *)nullReturn{
//    if ([self isEqual:@"NULL"] || [self isKindOfClass:[NSNull class]] || [self isEqual:[NSNull null]] || [self isEqual:NULL] || [[self class] isSubclassOfClass:[NSNull class]] || self == nil || self == NULL || [self isKindOfClass:[NSNull class]] || [[self stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]] length]==0 || [self isEqualToString:@"<null>"] || [self isEqualToString:@"(null)"]){
//        return @"22";
//    }else{
//        return (NSString *)self;
//    }
//}

- (void)backToAccountView{
    
    [self.navigationController popViewControllerAnimated:YES];
}



- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
